import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:lishopflu/base/base_import.dart';
import 'package:lishopflu/base/base_list_page.dart';
import 'package:lishopflu/base/view_import.dart';
import 'package:lishopflu/entity/address_bean.dart';

import 'address_manage_ctl.dart';

class AddressManagePage extends BaseListPage<AddressManageCtl>{

  @override
  void onCreate(BuildContext mContext) {
    setAppTitle('我的收货地址', actions: [
      IconButton(icon: Icon(Icons.add, color: Colors.white,), onPressed: () {
        controller.toAdd();
      }),
    ]);
  }

  @override
  Widget pageBody(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top:10, left: 10, right: 10),
      child: Obx(() => listBody(
        context,
        StaggeredGridView.countBuilder(
          itemBuilder: (BuildContext context, int index){
            return itemBuilder(context, index);
          },
          crossAxisCount: 1,
          mainAxisSpacing: 10.0,
          crossAxisSpacing: 5.0,
          staggeredTileBuilder: (int index) => StaggeredTile.fit(1),/*new StaggeredTile.count(2, index.isEven ? 2 : 1)*/
          itemCount: controller.mList.length,
        ),
      ),
      ),
    );
  }


  /// 列表的item
  Widget itemBuilder(BuildContext context, int index){
    AddressBean item = controller.mList[index];
    return GestureDetector(
      onTap: ((){
        controller.toEdit(item);
      }),
      child: Container(
        padding: EdgeInsets.only(top: 10, bottom: 10, left: 10, right: 10),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(10),
        ),
        child: Row(
          children: [
            CircleAvatar(child: Text(item.name.substring(0, 1)),),
            Expanded(
              flex: 1,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      Padding(
                        padding: EdgeInsets.only(left: 15, right: 15, top: 5, bottom: 5),
                        child: Text(item.name, style: TextStyle(fontWeight: FontWeight.bold),),
                      ),
                      Text(item.phone),
                    ],
                  ),
                  Padding(
                    padding: EdgeInsets.only(left: 15, right: 15, top: 5, bottom: 5),
                    child: Text(item.address),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

}